package com.ruoyi.storeroomuse.controller;

import java.util.List;

import com.ruoyi.storeroomuse.vo.StoreUseVO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.storeroomuse.domain.StoreroomUse;
import com.ruoyi.storeroomuse.service.IStoreroomUseService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 使用记录Controller
 * 
 * @author mqs
 * @date 2024-05-02
 */
@Controller
@RequestMapping("/storeroomuse/storeroomuse")
public class StoreroomUseController extends BaseController
{
    private String prefix = "storeroomuse/storeroomuse";

    @Autowired
    private IStoreroomUseService storeroomUseService;

    @RequiresPermissions("storeroomuse:storeroomuse:view")
    @GetMapping()
    public String storeroomuse()
    {
        return prefix + "/storeroomuse";
    }

    /**
     * 查询使用记录列表
     */
    @RequiresPermissions("storeUser:storeUser:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(StoreUseVO storeUseVO)
    {
        startPage();
        List<StoreUseVO> list = storeroomUseService.selectStoreroomUseList(storeUseVO);
        return getDataTable(list);
    }

    /**
     * 导出使用记录列表
     */
    @RequiresPermissions("storeUser:storeUser:export")
    @Log(title = "使用记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(StoreUseVO storeUseVO)
    {
        List<StoreUseVO> list = storeroomUseService.selectStoreroomUseList(storeUseVO);
        ExcelUtil<StoreUseVO> util = new ExcelUtil<StoreUseVO>(StoreUseVO.class);
        return util.exportExcel(list, "使用记录数据");
    }

    /**
     * 新增使用记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存使用记录
     */
    @RequiresPermissions("storeUser:storeUser:add")
    @Log(title = "使用记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(StoreUseVO storeUseVO)
    {
        return toAjax(storeroomUseService.insertStoreroomUse(storeUseVO));
    }

    /**
     * 修改使用记录
     */
    @RequiresPermissions("storeUser:storeUser:view")
    @GetMapping("/view/{storeId}")
    public String view(@PathVariable("storeId") Long storeId, ModelMap mmap)
    {
        StoreUseVO storeUseVO = storeroomUseService.selectStoreroomUseByStoreId(storeId);
        mmap.put("storeroomUse", storeUseVO);
        return prefix + "/view";
    }

    /**
     * 修改保存使用记录
     */
    @RequiresPermissions("storeroomuse:storeroomuse:edit")
    @Log(title = "使用记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(StoreroomUse storeroomUse)
    {
        return toAjax(storeroomUseService.updateStoreroomUse(storeroomUse));
    }

    /**
     * 删除使用记录
     */
    @RequiresPermissions("storeroomuse:storeroomuse:remove")
    @Log(title = "使用记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(storeroomUseService.deleteStoreroomUseByStoreIds(ids));
    }
}
